package com.mashibing.apidriver.controller;

import com.mashibing.apidriver.service.VerificationCodeService;
import org.mashibing.dto.ResponseResult;
import org.mashibing.request.VerificationCodeDTO;
import org.mashibing.response.TokenResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:
 * @create: 2024/6/28 11:02
 * @description:
 */
@RestController
public class VerificationCodeController {

    @Autowired
    VerificationCodeService verificationCodeService;

    /**
     * 司机获取数字验证码
     */
    @PostMapping("/verification_code")
    public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO) {
        return verificationCodeService.checkVerificationCode(verificationCodeDTO.getDriverPhone());
    }

    /**
     * 司机检验验证码
     */
    @PostMapping("/verification-code-check")
    public ResponseResult<TokenResponse> checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
        //获取司机手机号、验证码
        String driverPhone = verificationCodeDTO.getDriverPhone();
        String verificationCode = verificationCodeDTO.getVerificationCode();

        return verificationCodeService.checkCode(driverPhone,verificationCode);
    }
}
